package com.acmedcare.framework.spring.cloud.nacos.app;

import com.acmedcare.framework.exchange.center.ApplicationReadyEventListener;
import com.acmedcare.framework.exchange.center.OpenApiServer;
import com.acmedcare.framework.exchange.center.core.JmxContainerUtil;
import com.acmedcare.framework.exchange.center.core.storage.PluginRepository;
import com.acmedcare.framework.exchange.center.entity.dto.PluginCommand;
import com.acmedcare.framework.starter.control.GrpcLauncher;
import java.io.IOException;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import xyz.vopen.tiffany.swagger.EnableSwagger2;


@EnableSwagger2
@SpringBootApplication(scanBasePackageClasses = {OpenApiServer.class, PluginCommand.class,
    PluginRepository.class})
@EnableDiscoveryClient
public class OpenApiApplication  extends OpenApiServer {


  public static void main(String[] args) throws IOException {
    // new application
    ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder()
        .sources(OpenApiApplication.class)
        .web(WebApplicationType.SERVLET)
        .run(args);

    JmxContainerUtil.ServerPort = applicationContext.getEnvironment()
        .getProperty("local.server.port");
    ApplicationReadyEventListener readyEventListener = applicationContext
        .getBean(ApplicationReadyEventListener.class);
    readyEventListener.init();

    GrpcLauncher.startControl(applicationContext);
  }
}
